﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Data;
using System.Text.RegularExpressions;
using Runda.CMS.Web.Controls;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using Runda.CMS.Bll;

namespace Runda.CMS.Web.Controls.Lookup
{
    public class LookupDataPage:AppPage
    {
        // Fields
        private bool _columnsOnly;
        private string _extendedStyles;
        private string _lookupClass;
        private LookupMode _mode;
        private XmlDocument xmlDoc;

        //Properties
        protected string ExtendedStyles
        {
            get
            {
                return this._extendedStyles;
            }
        }

        protected LookupMode Mode
        {
            get
            {
                return this._mode;
            }
        }

        //Methods
        public LookupDataPage()
        {
            this._extendedStyles = string.Empty;
        }

        protected override void ConfigurePage()
        {
            this._mode = (LookupMode)int.Parse(base.Request.QueryString["Mode"]);
            if (!LookupPageBase.CheckBit((int)this.Mode, 4))
            {
                this._extendedStyles = "border-top: 0px;";
            }
            this._lookupClass = base.Request.QueryString["Class"];
            this.xmlDoc = LookupPageBase.GetXmlDocument("MapXml/" + this._lookupClass + ".xml");
            if (this.xmlDoc == null)
            {
                this.xmlDoc = new XmlDocument();
            }
            if (StringType.StrCmp(base.Request.QueryString["ColumnsOnly"], "1", false) == 0)
            {
                this._columnsOnly = true;
            }
            else
            {
                this._columnsOnly = false;
            }
        }

        public void ExecuteQuery()
        {
            this.RenderColumns();
            if (!this._columnsOnly)
            {
                this.RenderResults();
            }
        }

        private string GetFilter(ref XmlNode xmlN, string strSearchValue)
        {
            string str4;
            XmlNodeList list = xmlN.SelectNodes("condition|filter");
            if (list.Count == 0)
            {
                return "1=1";
            }
            if ((xmlN.Attributes.GetNamedItem("type") != null) && (StringType.StrCmp(xmlN.Attributes.GetNamedItem("type").Value.ToUpper(), "OR", false) == 0))
            {
                str4 = "OR";
            }
            else
            {
                str4 = "AND";
            }
            StringBuilder builder = new StringBuilder();
            builder.Append("(");
            int num5 = list.Count - 1;
            for (int i = 0; i <= num5; i++)
            {
                string str2;
                if (i > 0)
                {
                    builder.Append(" ");
                    builder.Append(str4);
                    builder.Append(" ");
                }
                if (list[i].Attributes.GetNamedItem("datatype") != null)
                {
                    str2 = list[i].Attributes.GetNamedItem("datatype").Value;
                }
                else
                {
                    str2 = "";
                }
                string str8 = list[i].Name.ToLower();
                if (StringType.StrCmp(str8, "condition", false) == 0)
                {
                    if (list[i].Attributes.GetNamedItem("value") != null)
                    {
                        string input = list[i].Attributes.GetNamedItem("value").Value;
                        MatchCollection matchs = new Regex(@"\[(\w+)\]").Matches(input);
                        int num4 = matchs.Count - 1;
                        for (int j = 0; j <= num4; j++)
                        {
                            string str7 = matchs[j].Groups[0].Value;
                            if (StringType.StrCmp(str7, "[本人]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, StringType.FromObject(this.Session["UserGUID"]));
                            }
                            else if (StringType.StrCmp(str7, "[当前公司]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, StringType.FromObject(this.Session["BUGUID"]));
                            }
                            else if (StringType.StrCmp(str7, "[今天]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, DateAndTime.Today.ToString("yyyy-MM-dd"));
                            }
                            else if (StringType.StrCmp(str7, "[本周初]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, DateAndTime.Today.AddDays((double)(1 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            }
                            else if (StringType.StrCmp(str7, "[本周末]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, DateAndTime.Today.AddDays((double)(7 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            }
                            else if (StringType.StrCmp(str7, "[本月初]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, DateAndTime.Today.ToString("yyyy-MM-01"));
                            }
                            else if (StringType.StrCmp(str7, "[本月末]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, DateAndTime.Today.AddMonths(1).AddDays((double)(0 - DateAndTime.Today.Day)).ToString("yyyy-MM-dd"));
                            }
                            else if (StringType.StrCmp(str7, "[本年初]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, DateAndTime.Today.ToString("yyyy-01-01"));
                            }
                            else if (StringType.StrCmp(str7, "[本年末]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, DateAndTime.Today.AddYears(1).AddMonths(1 - DateAndTime.Today.Month).AddDays((double)(0 - DateAndTime.Today.Day)).ToString("yyyy-MM-dd"));
                            }
                            else if (StringType.StrCmp(str7, "[searchvalue]", false) == 0)
                            {
                                input = input.Replace(matchs[j].Groups[0].Value, strSearchValue);
                            }
                            else
                            {
                                if (base.Request.QueryString[matchs[j].Groups[1].Value] == null)
                                {
                                    list[i].Attributes.GetNamedItem("operator").Value = "NO-OPR";
                                    break;
                                }
                                input = input.Replace(matchs[j].Groups[0].Value, base.Request.QueryString[matchs[j].Groups[1].Value]);
                            }
                        }
                        list[i].Attributes.GetNamedItem("value").Value = input;
                    }
                    string str6 = list.Item(i).Attributes.GetNamedItem("operator").Value.ToLower();
                    if (StringType.StrCmp(str6, "eq", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append("=");
                        if (StringType.StrCmp(str2, "money", false) == 0)
                        {
                            builder.Append(decimal.Parse(list[i].Attributes.GetNamedItem("value").Value).ToString());
                        }
                        else
                        {
                            builder.Append("'");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                    }
                    else if (StringType.StrCmp(str6, "ne", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append("<>");
                        if (StringType.StrCmp(str2, "money", false) == 0)
                        {
                            builder.Append(decimal.Parse(list[i].Attributes.GetNamedItem("value").Value).ToString());
                        }
                        else
                        {
                            builder.Append("'");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                    }
                    else if (StringType.StrCmp(str6, "gt", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append(">");
                        if (StringType.StrCmp(str2, "money", false) == 0)
                        {
                            builder.Append(decimal.Parse(list[i].Attributes.GetNamedItem("value").Value).ToString());
                        }
                        else
                        {
                            builder.Append("'");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                    }
                    else if (StringType.StrCmp(str6, "ge", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append(">=");
                        if (StringType.StrCmp(str2, "money", false) == 0)
                        {
                            builder.Append(decimal.Parse(list[i].Attributes.GetNamedItem("value").Value).ToString());
                        }
                        else
                        {
                            builder.Append("'");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                    }
                    else if (StringType.StrCmp(str6, "lt", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append("<");
                        if (StringType.StrCmp(str2, "money", false) == 0)
                        {
                            builder.Append(decimal.Parse(list[i].Attributes.GetNamedItem("value").Value).ToString());
                        }
                        else
                        {
                            builder.Append("'");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                    }
                    else if (StringType.StrCmp(str6, "le", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append("<=");
                        if (StringType.StrCmp(str2, "money", false) == 0)
                        {
                            builder.Append(decimal.Parse(list[i].Attributes.GetNamedItem("value").Value).ToString());
                        }
                        else
                        {
                            builder.Append("'");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                    }
                    else if (StringType.StrCmp(str6, "like", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append(" like '");
                        builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                        builder.Append("'");
                    }
                    else if (StringType.StrCmp(str6, "not-like", false) == 0)
                    {
                        builder.Append("NOT ");
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append(" like '");
                        builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                        builder.Append("'");
                    }
                    else if (StringType.StrCmp(str6, "not-null", false) == 0)
                    {
                        builder.Append("NOT ");
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append(" IS NULL");
                    }
                    else if (StringType.StrCmp(str6, "null", false) == 0)
                    {
                        builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                        builder.Append(" IS NULL");
                    }
                    else
                    {
                        string str3;
                        if (StringType.StrCmp(str6, "in", false) == 0)
                        {
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(" IN (");
                            if (StringType.StrCmp(str2, "money", false) == 0)
                            {
                                str3 = Regex.Replace(Strings.Trim(list[i].Attributes.GetNamedItem("value").Value), @"(\s|,)+", ",");
                                builder.Append(str3);
                            }
                            else
                            {
                                builder.Append("'");
                                str3 = Regex.Replace(Strings.Trim(list[i].Attributes.GetNamedItem("value").Value), @"(\s|,)+", ",").Replace("'", "''").Replace(",", "','");
                                builder.Append(str3);
                                builder.Append("'");
                            }
                            builder.Append(")");
                        }
                        else if (StringType.StrCmp(str6, "not-in", false) == 0)
                        {
                            builder.Append("NOT ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(" IN (");
                            if (StringType.StrCmp(str2, "money", false) == 0)
                            {
                                str3 = Regex.Replace(Strings.Trim(list[i].Attributes.GetNamedItem("value").Value), @"(\s|,)+", ",");
                                builder.Append(str3);
                            }
                            else
                            {
                                builder.Append("'");
                                str3 = Regex.Replace(Strings.Trim(list[i].Attributes.GetNamedItem("value").Value), @"(\s|,)+", ",").Replace("'", "''").Replace(",", "','");
                                builder.Append(str3);
                                builder.Append("'");
                            }
                            builder.Append(")");
                        }
                        else if (StringType.StrCmp(str6, "on", false) == 0)
                        {
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("='");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                        else if (StringType.StrCmp(str6, "on-or-after", false) == 0)
                        {
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                        else if (StringType.StrCmp(str6, "on-or-before", false) == 0)
                        {
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<='");
                            builder.Append(list[i].Attributes.GetNamedItem("value").Value.Replace("'", "''"));
                            builder.Append("'");
                        }
                        else if (StringType.StrCmp(str6, "yesterday", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddDays(-1.0).ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "Today", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddDays(1.0).ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "tomorrow", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddDays(1.0).ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddDays(2.0).ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "next-seven-days", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddDays(1.0).ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddDays(8.0).ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "last-seven-days", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddDays(-7.0).ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "next-week", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddDays((double)(7 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddDays((double)(14 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "last-week", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddDays((double)(-7 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddDays((double)(0 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "this-week", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddDays((double)(0 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddDays((double)(7 - DateAndTime.Today.DayOfWeek)).ToString("yyyy-MM-dd"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "next-month", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddMonths(1).ToString("yyyy-MM-01"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddMonths(2).ToString("yyyy-MM-01"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "last-month", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.AddMonths(-1).ToString("yyyy-MM-01"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.ToString("yyyy-MM-01"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "this-month", false) == 0)
                        {
                            builder.Append("(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(">='");
                            builder.Append(DateAndTime.Today.ToString("yyyy-MM-01"));
                            builder.Append("' AND ");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append("<'");
                            builder.Append(DateAndTime.Today.AddMonths(1).ToString("yyyy-MM-01"));
                            builder.Append("')");
                        }
                        else if (StringType.StrCmp(str6, "next-year", false) == 0)
                        {
                            builder.Append("year(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(")=");
                            builder.Append((int)(DateAndTime.Today.Year + 1));
                        }
                        else if (StringType.StrCmp(str6, "last-year", false) == 0)
                        {
                            builder.Append("year(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(")=");
                            builder.Append((int)(DateAndTime.Today.Year - 1));
                        }
                        else if (StringType.StrCmp(str6, "this-year", false) == 0)
                        {
                            builder.Append("year(");
                            builder.Append(list[i].Attributes.GetNamedItem("attribute").Value);
                            builder.Append(")=");
                            builder.Append(DateAndTime.Today.Year);
                        }
                        else
                        {
                            builder.Append("1=1");
                        }
                    }
                    continue;
                }
                if (StringType.StrCmp(str8, "filter", false) == 0)
                {
                    XmlNode node = list[i];
                    builder.Append(this.GetFilter(ref node, strSearchValue));
                }
            }
            builder.Append(")");
            return builder.ToString();
        }

        public void RenderColumnHeaders()
        {
            if (LookupPageBase.CheckBit((int)this.Mode, 2))
            {
                base.Response.Write("<tr><td height=\"10\"><table onmouseover=\"RenderToolTip();\" style=\"table-layout:fixed;\" class=\"listHeaderBar\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr>");
                XmlNodeList list = this.xmlDoc.SelectNodes("/lookup/columns/column");
                int num2 = list.Count - 1;
                for (int i = 0; i <= num2; i++)
                {
                    if ((list[i].Attributes.GetNamedItem("type") == null) || (StringType.StrCmp(list[i].Attributes.GetNamedItem("type").Value, "hidden", false) != 0))
                    {
                        base.Response.Write("<td class=\"column\" width=\"");
                        if (list[i].Attributes.GetNamedItem("width") != null)
                        {
                            base.Response.Write(list[i].Attributes.GetNamedItem("width").Value);
                        }
                        base.Response.Write("\"><nobr>");
                        if (i > 0)
                        {
                            base.Response.Write("<img style=\"vertical-align: middle\" src=\"../Content/Grid/bar_line.gif\">&nbsp;");
                        }
                        if (list[i].Attributes.GetNamedItem("name") != null)
                        {
                            base.Response.Write(System.Web.HttpUtility.HtmlEncode(list[i].Attributes.GetNamedItem("name").Value));
                        }
                        base.Response.Write("</nobr></td>");
                    }
                }
                base.Response.Write("<td width=\"18\">&nbsp;</td>");
                base.Response.Write("</tr></table><td></tr>");
            }
        }

        private void RenderColumns()
        {
            XmlNodeList list = this.xmlDoc.SelectNodes("/lookup/columns/column");
            int num2 = list.Count - 1;
            for (int i = 0; i <= num2; i++)
            {
                if ((list[i].Attributes.GetNamedItem("type") == null) || (StringType.StrCmp(list[i].Attributes.GetNamedItem("type").Value, "hidden", false) != 0))
                {
                    base.Response.Write("<col");
                    if (list[i].Attributes.GetNamedItem("width") != null)
                    {
                        base.Response.Write(" width=\"");
                        base.Response.Write(System.Web.HttpUtility.HtmlEncode(list[i].Attributes.GetNamedItem("width").Value));
                        base.Response.Write("\"");
                    }
                    if (list[i].Attributes.GetNamedItem("name") != null)
                    {
                        base.Response.Write(" name=\"");
                        base.Response.Write(System.Web.HttpUtility.HtmlEncode(list[i].Attributes.GetNamedItem("field").Value));
                        base.Response.Write("\"");
                    }
                    base.Response.Write(">");
                }
                else
                {
                    base.Response.Write("<col style=\"display:none\"");
                    if (list[i].Attributes.GetNamedItem("name") != null)
                    {
                        base.Response.Write(" name=\"");
                        base.Response.Write(System.Web.HttpUtility.HtmlEncode(list[i].Attributes.GetNamedItem("field").Value));
                        base.Response.Write("\"");
                    }
                    base.Response.Write(">");
                }
            }
            if (!LookupPageBase.CheckBit((int)this.Mode, 4))
            {
                base.Response.Write("<tr><td nowrap class=\"sel\" colspan=\"");
                base.Response.Write(list.Count);
                base.Response.Write("\"><img src=\"/Images/ico_18_role_x.gif\" align=\"absmiddle\" style=\"margin-right: 5px;\">");
                base.Response.Write("空");
                base.Response.Write("</td></tr>");
                if (!this._columnsOnly)
                {
                    base.Response.Write("<tr unselectable><td colspan=\"");
                    base.Response.Write(list.Count);
                    base.Response.Write("\" style=\"color:gray;padding-top:10px;padding-bottom:5px\">");
                    base.Response.Write("查询结果");
                    base.Response.Write(":</td></tr>");
                }
            }
            if (this._columnsOnly)
            {
                this.RenderInlineMessage("在查找框中输入一个记录名后点击查找。");
            }
        }

        private void RenderInlineMessage(string message)
        {
            base.Response.Write("<table class=\"inlineMsg\"><tr><td class=\"inlineMsg\" align=\"center\">");
            base.Response.Write(message);
            base.Response.Write("</td></tr></table>");
        }

        private void RenderResults()
        {
            int num;
            string str2;
            string str3;
            string filter;
            StringBuilder builder = new StringBuilder();
            string str = this.xmlDoc.DocumentElement.Attributes.GetNamedItem("entity").Value;
            if (this.xmlDoc.DocumentElement.Attributes.GetNamedItem("keyname") == null)
            {
                str3 = str + "Id";
            }
            else
            {
                str3 = this.xmlDoc.DocumentElement.Attributes.GetNamedItem("keyname").Value;
            }
            if (this.xmlDoc.DocumentElement.Attributes.GetNamedItem("icon") == null)
            {
                str2 = "";
            }
            else
            {
                str2 = this.xmlDoc.DocumentElement.Attributes.GetNamedItem("icon").Value;
            }
            XmlNodeList list = this.xmlDoc.SelectNodes("/lookup/columns/column");
            builder.Append(str3);
            int num5 = list.Count - 1;
            for (num = 0; num <= num5; num++)
            {
                builder.Append(",");
                builder.Append(list[num].Attributes.GetNamedItem("field").Value);
            }
            string sql = "SELECT " + builder.ToString() + " FROM " + str + " WHERE 1=1";
            XmlNode xmlN = this.xmlDoc.SelectSingleNode("/lookup/datasource/sql");
            if (xmlN != null)
            {
                sql = xmlN.InnerText;
            }
            xmlN = this.xmlDoc.SelectSingleNode("/lookup/datasource/filter");
            if (xmlN == null)
            {
                filter = "1=1";
            }
            else
            {
                filter = this.GetFilter(ref xmlN, Strings.Trim(base.Request.QueryString["searchvalue"]));
            }
            DataTable dataTable = new CommonBll().getDataFromSQL(sql.Replace("1=1", filter));
            int num4 = dataTable.Rows.Count - 1;
            for (num = 0; num <= num4; num++)
            {
                base.Response.Write("<tr oid=\"");
                base.Response.Write(System.Web.HttpUtility.HtmlEncode(dataTable.Rows[num][str3].ToString()));
                base.Response.Write("\">");
                bool flag = true;
                int num3 = list.Count - 1;
                for (int i = 0; i <= num3; i++)
                {
                    if ((list[i].Attributes.GetNamedItem("type") == null) || (StringType.StrCmp(list[i].Attributes.GetNamedItem("type").Value, "hidden", false) != 0))
                    {
                        base.Response.Write("<td nowrap class=\"sel\">");
                        if (flag && (StringType.StrCmp(str2, "", false) != 0))
                        {
                            base.Response.Write("<img src=\"");
                            base.Response.Write(System.Web.HttpUtility.HtmlEncode(str2));
                            base.Response.Write("\" class=\"lui\">");
                        }
                        flag = false;
                        base.Response.Write(System.Web.HttpUtility.HtmlEncode(dataTable.Rows[num][list[i].Attributes.GetNamedItem("field").Value].ToString()));
                        base.Response.Write("</td>");
                    }
                    else
                    {
                        base.Response.Write("<td nowrap style=\"display:none\">");
                        base.Response.Write(System.Web.HttpUtility.HtmlEncode(dataTable.Rows[num][list[i].Attributes.GetNamedItem("field").Value].ToString()));
                        base.Response.Write("</td>");
                    }
                }
                base.Response.Write("</tr>");
            }
            if (dataTable.Rows.Count == 0)
            {
                this.RenderInlineMessage("没有找到记录，请重试。");
            }
        }
    }
}
